package com.ruoyi.web.controller.wechatApplet;

import com.ruoyi.background.domain.AppWorkImg;
import com.ruoyi.background.service.IAppWorkImgService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/wechat/workImg")
public class WorkImgController extends BaseController {

    @Autowired
    private IAppWorkImgService workImgService;

    /**
     * 获取照片列表
     *
     * @param workImg 重新条件
     * @param type    0全部 1我的
     * @return list
     */
    @GetMapping("/getList/{type}")
    public TableDataInfo getWorkImgList(AppWorkImg workImg, @PathVariable Integer type) {
        if (type == 1) {
            workImg.setUserId(SecurityUtils.getUserId());
        } else {
            workImg.setStatus(0);
        }
        startPage();
        List<AppWorkImg> workImgList = workImgService.selectAppWorkImgList(workImg);
        return getDataTable(workImgList);
    }

    /**
     * 用户新增照片风采
     *
     * @param workImg 照片
     * @return 结果
     */
    @PostMapping("addWorkImg")
    public AjaxResult addUserWorkImg(@RequestBody AppWorkImg workImg) {
        return toAjax(workImgService.insertAppWorkImg(workImg));
    }


}
